<template>
  <div>
    <router-link to="/machine/AddMachine" v-if="role==2"><el-button>添加</el-button></router-link>
    <el-table
      :data="machineList"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="名称">
      </el-table-column>
      <el-table-column
        label="状态">
        <template slot-scope="scope">
          {{scope.row.state==0?"不可用":"可用"}}
        </template>
      </el-table-column>

      <el-table-column
        prop="description"
        label="描述">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <el-button  size="mini" @click="deleteMachine(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <router-view/>
  </div>
</template>

<script>
    export default {
        name: "machineList",
      data(){
          return {
            machineList:[],
            role:sessionStorage.getItem("role")
          }
      },
      created(){
        this.selectAll();
      },
      methods:{
        selectAll(){
          //发出ajax请求请求后端代码
          let url="/machine/selectAll";
          this.axios.get(url).then((resp)=>{
            this.machineList=resp.data;
          });
        },
        deleteMachine(id){
          this.axios.delete("/machine/delete/"+id).then((resp)=>{
            this.$message.success("删除成功！");
            this.selectAll();
          });
        }
      }
    }
</script>

<style scoped>

</style>
